package com.zc.remoteControl.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.ReactiveResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.framework.web.service.SysLoginService;
import com.zc.common.core.websocket.WebSocketService;
import com.zc.common.core.websocket.constant.WebSocketEvent;
import com.zc.manager.device.entity.DeviceProperty;
import com.zc.manager.device.service.IIotDeviceService;
import com.zc.manager.device.service.data.DeviceDataService;
import com.zc.operator.domain.ChargeStationAdjustPrice;
import com.zc.operator.domain.ChargeStationAdjustPriceAdditional;
import com.zc.operator.domain.ChargeStationPrice;
import com.zc.operator.domain.ChargeStationPriceType;
import com.zc.operator.mapper.ChargeStationAdjustPriceMapper;
import com.zc.operator.mapper.ChargeStationPriceTypeMapper;
import com.zc.remoteControl.service.RemoteInstructSendService;
import com.zc.util.ArithmeticUtils;
import com.zc.web.api.crud.entity.QueryParamEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.util.*;

import static com.zc.trendsDispatch.task.ChargeStationStrategyTask.Validation;
import static com.zc.util.RadixUtil.*;

/**
 * @Author glb
 * @Date 2023/12/12 10:42
 * @Version 1.0
 */
@Service
public class RemoteInstructSendServiceImpl implements RemoteInstructSendService {

    @Resource
    private DeviceDataService deviceDataService;//设备

    @Resource
    private IIotDeviceService iotDeviceService;

    @Resource
    private RedisCache redisCache;

    @Resource
    private SysLoginService loginService;

    @Resource
    private ChargeStationAdjustPriceMapper chargeStationAdjustPriceMapper;

    @Resource
    private ChargeStationPriceTypeMapper chargeStationPriceTypeMapper;

    @Override
    public Map<String, DeviceProperty> getRealData(String deviceId) {
        Flux<DeviceProperty> devicePropertyFlux = deviceDataService.queryEachOneProperties(deviceId, QueryParamEntity.of());
        List<DeviceProperty> block = devicePropertyFlux.collectList().block();
        Map<String, DeviceProperty> map = new HashMap<>();
        block.forEach(item -> {
            map.put(item.getProperty(), item);
        });
        return map;
    }

    @Override
    public Disposable sendMessage(String deviceId, String functionId, Map<String, Object> props) {
        Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
        if (keys.size() == 0) {
            // 生成令牌
            loginService.login("admin", "admin123", null, null);
            keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
        }
        String token = "";
        for (String key : keys) {
            token = key;
            break;
        }
        // 生成令牌
        token = token.replaceAll("login_tokens:", "");
        //String token = getLoginUser().getToken();
        String messageId = String.valueOf(UUID.randomUUID());
        String finalToken = token;
        Disposable subscribe = iotDeviceService.invokeFunction(deviceId, functionId, props, new HashMap<>())
                .doOnError(error -> WebSocketService.postEvent(finalToken, WebSocketEvent.REACTIVE, ReactiveResult.result(messageId, error.getMessage())))
                .subscribe(map -> WebSocketService.postEvent(finalToken, WebSocketEvent.REACTIVE, ReactiveResult.result(messageId, map)));
        return subscribe;
    }

    @Override
    public Map<String, Object> startCharge(String deviceId, String gunNum, int money, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            String random = "01";
            String card = "0000000000000000";
            money = (int) ArithmeticUtils.mul(money, 100);
            String balance = reverse(intHECToHex(money));
            int difference = 8 - balance.length();
            StringBuffer supplement = new StringBuffer();
            for (int i = 0; i < difference; i++) {
                supplement.append("0");
            }
            balance = balance + supplement;
            String serialNumber = dateFormat.format(new Date()) + deviceId + gunNum + random;
            String Assembly = "6830007C0034" + serialNumber + deviceId + gunNum + card + card + balance;
            String Validation = Validation(Assembly);
            Assembly = Assembly + Validation;
            System.out.println("Assembly__________________________>" + Assembly);
            String functionId = "sendInstruct";
            Map<String, Object> props = new HashMap<>();
            props.put("message", Assembly);
            sendMessage(deviceId, functionId, props);
            return new HashMap<String, Object>() {{
                put("transactionNum", serialNumber);
            }};

        }
        return null;
    }

    @Override
    public Map<String, Object> endCharge(String deviceId, String gunNum, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            String Assembly = "680C00000036" + deviceId + gunNum;
            String Validation = Validation(Assembly);
            Assembly = Assembly + Validation;
            System.out.println("Assembly__________________________>" + Assembly);
            String functionId = "sendInstruct";
            Map<String, Object> props = new HashMap<>();
            props.put("message", Assembly);
            sendMessage(deviceId, functionId, props);
        }
        return null;
    }

    @Override
    public Map<String, Object> getRealData(String deviceId, String gunNum, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            String Assembly = "680C00000012" + deviceId + gunNum;
            String Validation = Validation(Assembly);
            Assembly = Assembly + Validation;
            String functionId = "sendInstruct";
            Map<String, Object> props = new HashMap<>();
            props.put("message", Assembly);
            sendMessage(deviceId, functionId, props);
        }
        return null;
    }

    @Override
    public Map<String, Object> distributeQRCode(String deviceId, String gunNum, String QRCode, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            int length = QRCode.length();
            int countLength = length + 7;
            String QRCodeHex = convertStringToHex(QRCode);
            String Assembly = "68" + intHECToHex(countLength) + "0000009C" + gunNum + intHECToHex(length) + "00" + QRCodeHex;
            String Validation = Validation(Assembly);
            Assembly = Assembly + Validation;
            System.out.println("Assembly==========================》" + Assembly);
            String functionId = "sendInstruct";
            Map<String, Object> props = new HashMap<>();
            props.put("message", Assembly.toUpperCase());
            System.out.println("Assembly.toUpperCase()==========================》" + Assembly.toUpperCase());
            sendMessage(deviceId, functionId, props);
        }
        return null;
    }

    @Override
    public Map<String, Object> distributeBillingTemplate(List<String> deviceIds, Long priceTypeId, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            ChargeStationPrice chargeStationPrice = new ChargeStationPrice();
            chargeStationPrice.setPriceTypeId(priceTypeId);
            List<ChargeStationAdjustPrice> chargeStationAdjustPrices = chargeStationAdjustPriceMapper.selectDevicePriceList(chargeStationPrice);
            if (chargeStationAdjustPrices.size() > 0) {
                String electricPrice = "";
                String servicePrice = "";
                String electricPriceJ = "";
                String servicePriceJ = "";
                String electricPriceF = "";
                String servicePriceF = "";
                String electricPriceP = "";
                String servicePriceP = "";
                String electricPriceG = "";
                String servicePriceG = "";
                String electricPriceS = "";
                String servicePriceS = "";
                Map<Integer, String> map = new HashMap<>();
                ChargeStationAdjustPrice chargeStationAdjustPrice = chargeStationAdjustPrices.get(0);
                String pricing = chargeStationAdjustPrice.getPricing();
                if ("1".equals(pricing)) {
                    electricPrice = eightDecimalToHex((int) ArithmeticUtils.mul(Double.parseDouble(chargeStationAdjustPrice.getElectricPrice()), 100000));
                    servicePrice = eightDecimalToHex((int) ArithmeticUtils.mul(Double.parseDouble(chargeStationAdjustPrice.getServicePrice()), 100000));
                } else {
                    List<ChargeStationAdjustPriceAdditional> tableList = JSONObject.parseArray(chargeStationAdjustPrice.getTableData(), ChargeStationAdjustPriceAdditional.class);
                    for (ChargeStationAdjustPriceAdditional additional : tableList) {
                        int periodNum = additional.getPeriodNum();
                        if (1 == periodNum) {
                            electricPriceJ = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceJ = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (2 == periodNum) {
                            electricPriceF = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceF = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (3 == periodNum) {
                            electricPriceP = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceP = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (4 == periodNum) {
                            electricPriceG = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceG = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (5 == periodNum) {
                            electricPriceS = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceS = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        }
                        String interval = additional.getInterval();
                        String[] split = interval.split("],");
                        for (String time : split) {
                            String timeReplace = time.replace("[", "").replace("]", "").replace("\"", "");
                            String[] timeParagraph = timeReplace.split(",");
                            String[] start = timeParagraph[0].split(":");
                            String[] end = timeParagraph[1].split(":");
                            LocalTime startTime = LocalTime.of(Integer.parseInt(start[0]), Integer.parseInt(start[1])); // 9:00 AM
                            LocalTime endTime = null; // 6:00 PM
                            if (Integer.parseInt(end[0]) == 24) {
                                endTime = LocalTime.of(23, 30); // 6:00 PM
                            } else {
                                endTime = LocalTime.of(Integer.parseInt(end[0]), Integer.parseInt(end[1])); // 6:00 PM
                            }
                            List<Integer> halfHours = decomposeToHalfHours(startTime, endTime);
                            int num = halfHours.size() - 1;
                            if (Integer.parseInt(end[0]) == 24) {
                                num = halfHours.size();
                            }
                            for (int i = 0; i < num; i++) {
                                LocalTime localTime = startTime.plusMinutes(i * 30);
                                int minuteCount = countMinutes(localTime);
                                int timeInterval = minuteCount / 30;
                                int type = periodNum == 5 ? 4 - 1 : periodNum - 1;
                                map.put(timeInterval, "0" + type);
                                //map.put(timeInterval, (i + 1) + ": " + startTime.plusMinutes(i * 30) + " - " + startTime.plusMinutes((i + 1) * 30));
                            }
                        }
                    }
                }
                String price = "";
                String planning = "";
                if ("1".equals(pricing)) {
                    price = electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice;
                    planning = "020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202";
                } else {
                    StringBuffer stringBuffer = new StringBuffer();
                    price = electricPriceJ + servicePriceJ + electricPriceF + servicePriceF + electricPriceP + servicePriceP + electricPriceG + servicePriceG;
                    for (int i = 0; i < 48; i++) {
                        if (map.containsKey(i)) {
                            stringBuffer.append(map.get(i));
                        } else {
                            stringBuffer.append("02");
                        }
                    }
                    planning = stringBuffer.toString();
                }
                for (int i = 0; i < deviceIds.size(); i++) {
                    String reply = "685E00000058" + deviceIds.get(i) + "0100" + price + "00" + planning;
                    String crcValidation = Validation(reply);
                    reply = reply + crcValidation;
                    String functionId = "sendInstruct";
                    Map<String, Object> props = new HashMap<>();
                    props.put("message", reply);
                    sendMessage(deviceIds.get(i), functionId, props);
                }

            } else {
                ChargeStationPriceType chargeStationPriceType = chargeStationPriceTypeMapper.selectChargeStationPriceTypeByPriceTypeId(priceTypeId);
                String electricPrice = eightDecimalToHex((int) ArithmeticUtils.mul(chargeStationPriceType.getFoundationElectricCharge().doubleValue(), 100000));
                String servicePrice = eightDecimalToHex((int) ArithmeticUtils.mul(chargeStationPriceType.getFoundationServiceFee().doubleValue(), 100000));
                String price = electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice;
                String planning = "020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202";
                for (int j = 0; j < deviceIds.size(); j++) {
                    String reply = "685E00000058" + deviceIds.get(j) + "0100" + price + "00" + planning;
                    String crcValidation = Validation(reply);
                    reply = reply + crcValidation;
                    String functionId = "sendInstruct";
                    Map<String, Object> props = new HashMap<>();
                    props.put("message", reply);
                    sendMessage(deviceIds.get(j), functionId, props);
                }
            }
        }
        return null;
    }

    @Override
    public Map<String, Object> distributeBillingTemplates(List<String> deviceIds, Long priceTypeId, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            ChargeStationPrice chargeStationPrice = new ChargeStationPrice();
            chargeStationPrice.setPriceTypeId(priceTypeId);
            List<ChargeStationAdjustPrice> chargeStationAdjustPrices = chargeStationAdjustPriceMapper.selectDevicePriceList(chargeStationPrice);
            if (chargeStationAdjustPrices.size() > 0) {
                String electricPrice = "";
                String servicePrice = "";
                String electricPriceJ = "";
                String servicePriceJ = "";
                String electricPriceF = "";
                String servicePriceF = "";
                String electricPriceP = "";
                String servicePriceP = "";
                String electricPriceG = "";
                String servicePriceG = "";
                String electricPriceS = "";
                String servicePriceS = "";
                Map<Integer, String> map = new HashMap<>();
                ChargeStationAdjustPrice chargeStationAdjustPrice = chargeStationAdjustPrices.get(0);
                String pricing = chargeStationAdjustPrice.getPricing();
                if ("1".equals(pricing)) {
                    electricPrice = eightDecimalToHex((int) ArithmeticUtils.mul(Double.parseDouble(chargeStationAdjustPrice.getElectricPrice()), 100000));
                    servicePrice = eightDecimalToHex((int) ArithmeticUtils.mul(Double.parseDouble(chargeStationAdjustPrice.getServicePrice()), 100000));
                } else {
                    List<ChargeStationAdjustPriceAdditional> tableList = JSONObject.parseArray(chargeStationAdjustPrice.getTableData(), ChargeStationAdjustPriceAdditional.class);
                    for (ChargeStationAdjustPriceAdditional additional : tableList) {
                        int periodNum = additional.getPeriodNum();
                        if (1 == periodNum) {
                            electricPriceJ = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceJ = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (2 == periodNum) {
                            electricPriceF = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceF = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (3 == periodNum) {
                            electricPriceP = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceP = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (4 == periodNum) {
                            electricPriceG = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceG = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        } else if (5 == periodNum) {
                            electricPriceS = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getElectricityPrice(), 100000));
                            servicePriceS = eightDecimalToHex((int) ArithmeticUtils.mul(additional.getServiceCharge(), 100000));
                        }
                        String interval = additional.getInterval();
                        String[] split = interval.split("],");
                        for (String time : split) {
                            String timeReplace = time.replace("[", "").replace("]", "").replace("\"", "");
                            String[] timeParagraph = timeReplace.split(",");
                            String[] start = timeParagraph[0].split(":");
                            String[] end = timeParagraph[1].split(":");
                            LocalTime startTime = LocalTime.of(Integer.parseInt(start[0]), Integer.parseInt(start[1])); // 9:00 AM
                            LocalTime endTime = null; // 6:00 PM
                            if (Integer.parseInt(end[0]) == 24) {
                                endTime = LocalTime.of(23, 30); // 6:00 PM
                            } else {
                                endTime = LocalTime.of(Integer.parseInt(end[0]), Integer.parseInt(end[1])); // 6:00 PM
                            }
                            List<Integer> halfHours = decomposeToHalfHours(startTime, endTime);
                            int num = halfHours.size() - 1;
                            if (Integer.parseInt(end[0]) == 24) {
                                num = halfHours.size();
                            }
                            for (int i = 0; i < num; i++) {
                                LocalTime localTime = startTime.plusMinutes(i * 30);
                                int minuteCount = countMinutes(localTime);
                                int timeInterval = minuteCount / 30;
                                int type = periodNum == 5 ? 4 - 1 : periodNum - 1;
                                map.put(timeInterval, "0" + type);
                            }
                        }
                    }
                }
                String price = "";
                String planning = "";
                if ("1".equals(pricing)) {
                    price = electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice;
                    planning = "020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202";
                } else {
                    StringBuffer stringBuffer = new StringBuffer();
                    price = electricPriceJ + servicePriceJ + electricPriceF + servicePriceF + electricPriceP + servicePriceP + electricPriceG + servicePriceG;
                    for (int i = 0; i < 48; i++) {
                        if (map.containsKey(i)) {
                            stringBuffer.append(map.get(i));
                        } else {
                            stringBuffer.append("02");
                        }
                    }
                    planning = stringBuffer.toString();
                }
                for (int i = 0; i < deviceIds.size(); i++) {
                    String reply = "685E0000000A" + deviceIds.get(i) + "0100" + price + "00" + planning;
                    String crcValidation = Validation(reply);
                    reply = reply + crcValidation;
                    String functionId = "sendInstruct";
                    Map<String, Object> props = new HashMap<>();
                    props.put("message", reply);
                    sendMessage(deviceIds.get(i), functionId, props);
                }

            } else {
                ChargeStationPriceType chargeStationPriceType = chargeStationPriceTypeMapper.selectChargeStationPriceTypeByPriceTypeId(priceTypeId);
                String electricPrice = eightDecimalToHex((int) ArithmeticUtils.mul(chargeStationPriceType.getFoundationElectricCharge().doubleValue(), 100000));
                String servicePrice = eightDecimalToHex((int) ArithmeticUtils.mul(chargeStationPriceType.getFoundationServiceFee().doubleValue(), 100000));
                String price = electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice + electricPrice + servicePrice;
                String planning = "020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202";
                for (int j = 0; j < deviceIds.size(); j++) {
                    String reply = "685E0000000A" + deviceIds.get(j) + "0100" + price + "00" + planning;
                    String crcValidation = Validation(reply);
                    reply = reply + crcValidation;
                    String functionId = "sendInstruct";
                    Map<String, Object> props = new HashMap<>();
                    props.put("message", reply);
                    sendMessage(deviceIds.get(j), functionId, props);
                }
            }
        }
        return null;
    }

    @Override
    public Map<String, Object> transactionRecordConfirmation(String deviceId, String transactionNum, String confirm, String deviceType) {
        String reply = "681500000040" + transactionNum + confirm;
        String crcValidation = Validation(reply);
        reply = reply + crcValidation;
        String functionId = "sendInstruct";
        Map<String, Object> props = new HashMap<>();
        props.put("message", reply);
        sendMessage(deviceId, functionId, props);
        return null;
    }

    public static List<Integer> decomposeToHalfHours(LocalTime startTime, LocalTime endTime) {
        List<Integer> result = new ArrayList<>();
        LocalTime stopTime = LocalTime.of(00, 00);
        LocalTime currentTime = startTime;
        while (!currentTime.isAfter(endTime)) {
            result.add(result.size()); // 使用列表的大小作为每半个小时的代表数字
            currentTime = currentTime.plusMinutes(30);
            if (currentTime.isAfter(endTime)) {
                break; // 如果加上30分钟后超过了结束时间，则不添加这个时间段
            }
            if (stopTime.equals(currentTime)) {
                break;
            }
        }
        return result;
    }

    public static int countMinutes(LocalTime time) {
        long minutesDifference = time.toNanoOfDay() / 60_000_000_000L; // 计算分钟差，通过转换为纳秒然后除以每分钟的纳秒数
        return (int) minutesDifference;
    }


    public static Map<String, Object> distributeQRCodes(String deviceId, String gunNum, String QRCode, String deviceType) {
        if ("YTSN-CDZ-N01".equals(deviceType)) {
            int length = QRCode.length();
            int countLength = length + 7;
            String QRCodeHex = convertStringToHex(QRCode);
            String Assembly = "68" + intHECToHex(countLength) + "0000009C" + gunNum + intHECToHex(length) + "00" + QRCodeHex;
            String Validation = Validation(Assembly);
            Assembly = Assembly + Validation;
            String functionId = "sendInstruct";
            Map<String, Object> props = new HashMap<>();
            props.put("message", Assembly.toUpperCase());
            //sendMessage(deviceId, functionId, props);
            System.out.println(Assembly.toUpperCase());
        }
        return null;
    }


    public static void main(String[] args) {
        //distributeQRCodes("44030900020002","01","http://xazdyl.com/xm/44030900020002|1","YTSN-CDZ-N01");
        distributeQRCodes("44030900020002", "01", "https://www.sdzctech.cn:4433/appQrCode?id=6&code=1004&deviceId=44030900020002&gunPos=4403090002000201", "YTSN-CDZ-N01");
        //distributeQRCodes("44030900020002","01","http://xazdyl.com/xm/44030900020002|1","YTSN-CDZ-N01");
        //distributeQRCodes("44030900020002","02","http://xazdyl.com/xm/44030900020002|2","YTSN-CDZ-N01");
        distributeQRCodes("44030900020002","01","https://www.sdzctech.cn:4433/appQrCode?id=6&code=1004&deviceId=44030900020002&gunPos=4403090002000201","YTSN-CDZ-N01");
        distributeQRCodes("44030900020002","02","https://www.sdzctech.cn:4433/appQrCode?id=6&code=1004&deviceId=44030900020002&gunPos=4403090002000202","YTSN-CDZ-N01");
        String hexString = "68747470733a2f2f7777772e73647a63746563682e636e3a343433332f6170705172436f64653f69643d3626636f64653d313030342664657669636549643d34343033303930303032303030322667756e506f733d34343033303930303032303030323031";
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < hexString.length(); i += 2) {
            String hex = hexString.substring(i, i + 2);
            int asciiCode = Integer.parseInt(hex, 16);
            stringBuilder.append(Character.toString((char) asciiCode));
        }
        String result = stringBuilder.toString();
        //System.out.println("result:"+result);
    }
}
